function [X, Y] = fker_xymap(h, w, angle)
%FKER_XYMAP The X-Y Coordinate Map for Filter Kernel Generation
%
%   [X, Y] = FKER_XYMAP(h, w);
%
%       Returns two matrix X and Y, both of size [h, w].
%
%       In particular, each row of X is the same: -xe, -xe+1, ..., xe.
%       each column of Y is the same: -ye, -ye+1, ..., ye.
%
%       Here, xe = (w-1)/2 and ye = (h-1)/2.
%
%   [X, Y] = FKER_XYMAP(h, w, angle);
%
%       Returns the kernels rotated by the given angle.
%

% Created by Dahua Lin, on April 3, 2012
%

%% argument

if nargin < 3
    angle = 0;
end

%% main

xe = (w - 1) / 2;
ye = (h - 1) / 2;

X = -xe : xe;
X = X(ones(h, 1), :);

Y = (-ye : ye).';
Y = Y(:, ones(1, w));

if angle ~= 0
    r = deg2rad(angle);
        
    X2 = X * cos(r) - Y * sin(r);
    Y2 = Y * cos(r) + X * sin(r);
    
    X = X2;
    Y = Y2;
end


